import 'package:flutter/material.dart';

/// 测试长列表滑动
/// 1. 写一个长列表测试
/// 2. 记录应用状态
/// 3. 保存结果
/// 4. 运行测试
/// 5. 查看结果(build路径下)

class ListApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final String appTitle = 'Long List Demo';
    return MaterialApp(
      title: appTitle,
      theme: ThemeData(primarySwatch: Colors.red),
      home: ListAppPage(title: appTitle),
    );
  }
}

class ListAppPage extends StatefulWidget {
  final String title;

  ListAppPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() => ListAppPageState();
}

class ListAppPageState extends State<ListAppPage> {
  final List<String> items = List<String>.generate(10000, (i) => 'Item $i');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ListView.builder(
          key: Key('long_list'),
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
                title: Text('${items[index]}', key: Key('item_${index}_text')));
          }),
    );
  }
}
